﻿using System;
using UnityEngine;
using UnityEngine.UI;

namespace JEngine.Framework
{
    /// <summary>
    /// 面板,所有的窗体必须继承该类
    /// </summary>
    [RequireComponent(typeof(Canvas))]
    [RequireComponent(typeof(GraphicRaycaster))]
    public abstract class Panel : UIContainer
    {
        protected abstract void OnLoad(params object[] parameters);

        protected override void InitComponent()
        {
            base.InitComponent();
        }

        protected void Start()
        {
            OnLoad(parameters);

        }

        /// <summary>
        /// 设置排序值
        /// </summary>
        /// <param name="sortingOrder"></param>
        public void SetSortingOrder(int sortingOrder)
        {
            this.canvas.overrideSorting = true;
            this.canvas.sortingOrder = sortingOrder;
        }

        /// <summary>
        /// 隐藏面板
        /// </summary>
        public void HidePanel()
        {
            Engine.UI.ClosePanel(this.GetType().Name, false);
        }

        /// <summary>
        /// 关闭面板
        /// </summary>
        public void ClosePanel()
        {
            Engine.UI.ClosePanel(this.GetType().Name, true);
        }
    }
}